﻿@model Aga.GestionDeArchivos.Web.Models.Guarda.SalidaDocumentacionModel
@{
    ViewBag.Title = "Salida en Consulta de Contenedor Abierto";
    Layout = "~/Views/Shared/_InternalLayout.cshtml";
}
@section Scripts
{
    <style>
	    .ui-autocomplete-loading { background: white url('images/ui-anim_basic_16x16.gif') right center no-repeat; }
	</style>

    <script type="text/javascript">
        function showLoading() {
            $('img[name="loadingimg"]').each(function () { $(this).show() });
        }

        function hideLoading() {
            $('img[name="loadingimg"]').each(function () { $(this).hide() });
        }

        function submitAction(action, item) {
            $('#SubmitAction').val('Remove');
            $('#RemoveItemId').val(item);

            $('form').submit();
        }

        $(document).ready(function () {

            $('#Nombre').change(function () {
                var nombre = $(this).val();

                if (nombre != '') {
                    showLoading();

                    $.ajax({
                        url: '@VirtualPathUtility.ToAbsolute("~/Guarda/BuscarCliente")',
                        data: { nombre: nombre },
                        type: 'POST',
                        dataType: 'json',
                        success: function (result) {
                            if (result != undefined) {
                                $('#ClienteId').val(result.Id);
                                $('#Nombre').val(result.Nombre);
                                $('#DomicilioEntrega').val(result.Domicilio);
                                $('#Responsable').val(result.Responsable);
                                $('#Caja').focus();
                                $('#Caja').select();
                            }
                            else {
                                alert('Ha ocurrido un error obteniendo los datos del cliente. Vuelva a leer la caja.');
                            }
                            hideLoading();
                        },
                        error: function (e) {
                            hideLoading();
                            alert('Ha ocurrido un error obteniendo los datos del cliente. Vuelva a leer la caja.\n\n' + e);
                        }
                    })
                }
            });

            $('#Detalle').change(function () {
                if ($('#Caja').val() != '') {
                    if ($('#Detalle').val() != '') {
                        $('input[type="submit"][name="agregar"]').click();
                    }
                }
                else {
                    $('#Caja').focus();
                    $('#Caja').select();
                }
            });

            $('#@Model.Focus').focus();
            $('#@Model.Focus').select();

        });
    </script>
}
<div id="content">
    <table width="100%" border="0" cellpadding="0" cellspacing="0" class="box-style1">
        <tr>
            <td id="box2">
                <h2>
                    Salida en Consulta de Contenedor Abierto</h2>
                @using (Html.BeginForm())
                {
                    <p>
                        @Html.HiddenFor(model => model.ClienteId)
                        @Html.HiddenFor(model => model.SubmitAction)
                        @Html.HiddenFor(model => model.RemoveItemId)

                        @Html.LabelFor(model => model.Fecha):
                        <br />
                        @Html.TextBoxFor(model => model.Fecha, new { @class = "text115" }) <span style="color:gray">(Formato: dd/mm/aaaa hh:mm - Ejemplo: 31/12/2010 15:30)</span>
                        <br />
                        @Html.LabelFor(model => model.Nombre):
                        <br />
                        @Html.TextBoxFor(model => model.Nombre, new { @class = "extralargetext" })
                        <img name="loadingimg" src="@Url.Content("~/Content/images/loading.gif")" class="loadingfieldimage" alt="loading..." />
                        <br />
                        @Html.LabelFor(model => model.DomicilioEntrega):
                        <br />
                        @Html.TextBoxFor(model => model.DomicilioEntrega, new { style = "width:600px", @class = "extralargetext" })
                        <img name="loadingimg" src="@Url.Content("~/Content/images/loading.gif")" class="loadingfieldimage" alt="loading..." />
                        <br />
                        @Html.LabelFor(model => model.Responsable):
                        <br />
                        @Html.TextBoxFor(model => model.Responsable, new { style = "width:600px", @class = "extralargetext" })
                        <img name="loadingimg" src="@Url.Content("~/Content/images/loading.gif")" class="loadingfieldimage" alt="loading..." />
                    </p>
                    <table class="abm">
                        <tr>
                            <th>Cantidad</th>
                            <th>Caja</th>
                            <th>Detalle</th>
                            <th></th>
                        </tr>
                        <tr>
                            <td><input type="text" value="1" name="cantidad" class="smalltext" readonly="readonly" disabled="disabled" /></td>
                            <td>@Html.TextBoxFor(m => m.Caja, new { @class = "mediumtext" })</td>
                            <td>@Html.TextBoxFor(m => m.Detalle, new { @class = "text425" })</td>
                            <td><span class="buttons"><input type="submit" value="Agregar" name="agregar" onclick="javascript:$('#SubmitAction').val('Add')" /></span></td>
                        </tr>
                        @foreach (var item in Model.Items)
                        {
                        <tr>
                            <td>@item.Cantidad</td>
                            <td>@item.Caja</td>
                            <td>@item.Detalle</td>
                            <td align="center"><a href="#" onclick="javascript:submitAction('Remove', '@String.Format("{0}:{1}", item.Caja, item.Detalle)')">Remover</a></td>
                        </tr>
                        }
                    </table>
                    <p>
                        @Html.LabelFor(model => model.Observaciones):
                        <br />
                        @Html.TextAreaFor(model => model.Observaciones, new { width = "690px" })
                    </p>
                    <p class="buttons alignleft">
                        @Html.ActionLink("Cancelar", "SalidaDocumentacion", "Guarda")
                        <input type="submit" value="Confirmar" onclick="javascript:$('#SubmitAction').val('Close')"/>
                    </p>
                }
            </td>
        </tr>
    </table>
</div>
